class Scope(object):
    
    SYM_PATH_SEP = '->'

    def __init__(self, parent=None):
        self.__parent = parent
        self.__symtab = {}
        
    def define_symbol(self, name, value):
        self.__symtab[name] = value
        
    def define_symbols(self, names_values):
        self.__symtab.update(names_values)
        
    def set_symbol(self, name, value):
        if name in self.__symtab:
            self.__symtab[name] = value
        elif self.__parent:
            self.__parent.set_symbol(name, value)
        else:
            raise UnknownSymbolException(name)
        
    def set_symbols(self, names_values):
        for name, value in names_values.items():
            self.set_symbol(name, value)
        
    def lookup(self, symbol_name):
        
        res = None
        
        components = symbol_name.split(self.SYM_PATH_SEP)
        for comp in components:
            if res is None:
                try:
                    res = self.__symtab[comp]
                except KeyError:
                    break
            else:
                try:
                    res = getattr(res, comp)
                except AttributeError:
                    return None
        
        if res is None and self.__parent:
            res = self.__parent.lookup(symbol_name)
            
        return res

class UnknownSymbolException(Exception):
    pass